package com.cmict.data.system.api.dept;

import com.cmict.data.framework.common.pojo.CommonResult;
import com.cmict.data.framework.common.util.collection.CollectionUtils;
import com.cmict.data.system.api.dept.dto.PostDTO;
import com.cmict.data.system.api.user.dto.AdminUserRespDTO;
import com.cmict.data.system.enums.ApiConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.Collection;
import java.util.List;
import java.util.Map;

@FeignClient(name = ApiConstants.NAME) // TODO awesome：fallbackFactory =
@Api(tags = "RPC 服务 - 岗位")
public interface PostApi {

    String PREFIX = ApiConstants.PREFIX + "/post";

    @GetMapping(PREFIX + "/valid")
    @ApiOperation("校验岗位是否合法")
    @ApiImplicitParam(name = "ids", value = "岗位编号数组", example = "1,2", required = true, allowMultiple = true)
    CommonResult<Boolean> validPosts(@RequestParam("ids") Collection<Long> ids);

    @GetMapping(PREFIX + "/getPosts")
    @ApiOperation("校验岗位是否合法")
    @ApiImplicitParam(name = "ids", value = "岗位编号数组", example = "1,2", required = true, allowMultiple = true)
    CommonResult<List<PostDTO>> getPosts(@RequestParam("ids") Collection<Long> ids);

    @GetMapping(PREFIX + "/getPosts-By-ids-join")
    @ApiOperation("校验岗位是否合法")
    @ApiImplicitParam(name = "ids", value = "岗位编号数组", example = "1,2", required = true, allowMultiple = true)
    CommonResult<List<PostDTO>> getPostsByIdsJoin(@RequestParam("ids") String ids);


    default Map<Long, PostDTO> getPortMap(Collection<Long> ids) {
        String idList = StringUtils.join(ids, ",");
        return CollectionUtils.convertMap(getPostsByIdsJoin(idList).getCheckedData(), PostDTO::getId);
    }

    default List<Map<String, Object>> getPostsByPostNamesMap(Collection<Long> names) {
        String idList = StringUtils.join(names, ",");
        return getPostsByPostNamesInner(idList).getCheckedData();
    }

    @GetMapping(PREFIX + "/getPostsByPostNamesInner")
    @ApiOperation("校验岗位是否合法")
    CommonResult<List<Map<String, Object>>> getPostsByPostNamesInner(@RequestParam("names") String names);


    @GetMapping(PREFIX + "/getPostsByPostNames")
    @ApiOperation("校验岗位是否合法")
    @ApiImplicitParam(name = "names", value = "岗位编号数组", example = "1,2", required = true, allowMultiple = true)
    CommonResult<List<Map<String, Object>>> getPostsByPostNames(@RequestParam("names") Collection<String> names);

    @GetMapping(PREFIX + "/list")
    @ApiOperation("获取职位列表")
    CommonResult<List<PostDTO>> selectListAll();
}
